package com.mccken.demo.maiwei;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentSkipListMap;

import com.alicp.jetcache.Cache;
import com.alicp.jetcache.embedded.CaffeineCacheBuilder;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-01-30 00:06
 **/
public class MessageCacheDemo {
	public static long id = 5323742345749856383L;

	private static Cache<Long, ConcurrentSkipListMap<Long, List<MessageDTO>>> cache = CaffeineCacheBuilder.createCaffeineCacheBuilder().buildCache();

	/**
	 * 50w条数据，大概 20M 内存
	 */
	public static void main(String[] args) throws InterruptedException {
		System.out.println(111);
		Thread.sleep(30000);
		
		new Thread(() -> {
			init();
		}).start();

		while (true) {
			Thread.sleep(3000);
		}
	}

	public static void init() {

		for (int i = 0; i < 100; i++) {
			long l = id + i;
		
			ConcurrentSkipListMap<Long, List<MessageDTO>> map = new ConcurrentSkipListMap<>();
			List<MessageDTO> list = new ArrayList<>();
			for (int j = 0; j < 5000; j++) {
				MessageDTO e = new MessageDTO();
				e.setUserId(id + 111);
				list.add(e);	
				map.put(l+j, list);
			}
			cache.put(l,map);
		}
		System.out.println();
	}

}
